<?php
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------
//赞片CMS
namespace app\common\model;
use think\Model;
class Tag extends Model{
	// 更新Tag 不采用关联模式(用于手动更新关联,删除之前的数据后重新写入)
	public function tag_updata($id,$sid,$tag=''){
		$rs=db('Tag');
		$data['tag_id'] = $id;
		$data['tag_sid'] = $sid;
		$rs->where($data)->delete();
		if(!empty($tag) && !empty($id) && !empty($sid)){
            if (is_array($tag)) {
                $tags = $tag;
            } else {
                $tags = explode(',',trim($tag));
            }
            $tags = array_filter(array_unique($tags));			
		    foreach($tags as $key=>$val){
			    $datas[$key]['tag_id'] = $id;
			    $datas[$key]['tag_sid'] = $sid;
			    $datas[$key]['tag_name'] = $val;
		    }
		    if(isset($datas)){
		        $rs->insertAll($datas);   
		    }
		}
	}	
	public function vod(){
        return $this->hasMany('Vod','vod_id','tag_id');
    }
	public function actorid(){
        return $this->hasMany('Actor','actor_vid','tag_id');
    }
	public function storyid(){
        return $this->hasMany('Story','story_vid','tag_id');
    }	
}